/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */
var twoSum = function(nums, target) {
  let map = new Map();
  for(let i = 0; i < nums.length; i++) {
    if(map[target - nums[i]] != undefined) {
      return [map[target - nums[i]], i];
    }
    map[nums[i]] = i;
  }
};

let nums = [2,7,11,15], target = 9;
console.log(twoSum(nums, target));
nums = [3,2,4], target = 6
console.log(twoSum(nums, target));
nums = [3,3], target = 6
console.log(twoSum(nums, target));
